#include "common.h"

#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <iostream>

std::list<std::string> getIpsFromDNS(const std::string &dns)
{
    std::list<std::string> ips;
    struct hostent *hptr = gethostbyname(dns.c_str());
    if (hptr == NULL) {
        std::cout << "gethostbyaddr failed" << std::endl;
        return ips;
    }

    for (int i = 0; hptr->h_addr_list[i] != NULL; i++) {
        ips.insert(ips.end(), inet_ntoa(*(struct in_addr *)hptr->h_addr_list[i]));
    }

    return ips;
}